package cn.com.lsy.product.lepao.controller;

import cn.com.lsy.product.lepao.common.Constant;
import cn.com.lsy.product.lepao.controller.base.BaseController;
import cn.com.lsy.product.lepao.model.entities.*;
import cn.com.lsy.product.lepao.model.mt.entities.CityListDto;
import cn.com.lsy.product.lepao.model.mt.entities.GetsStoreAlbumDto;
import cn.com.lsy.product.lepao.model.mt.entities.IconListDto;
import cn.com.lsy.product.lepao.model.mt.entities.StoreIconListDto;
import cn.com.lsy.product.lepao.request.*;
import cn.com.lsy.product.lepao.response.*;
import cn.com.lsy.product.lepao.response.base.ApiResponseEnum;
import cn.com.lsy.product.lepao.response.base.BaseRet;
import cn.com.lsy.product.lepao.response.base.PageInfo;
import cn.com.lsy.product.lepao.service.*;
import cn.com.lsy.product.lepao.util.CommonFunctionUtil;
import cn.com.lsy.product.lepao.util.DozerMapperUtil;
import com.alibaba.fastjson.JSONArray;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

@Api(value = "场馆接口", tags = "场馆接口")
@RestController
@RequestMapping(value = "/lepao/console/doAuth")
public class StoreController extends BaseController {

    private Logger log = Logger.getLogger(StoreController.class);
    Mapper mapper = new DozerBeanMapper();

    private Base64.Decoder decoder = Base64.getDecoder();
    private Base64.Encoder encoder = Base64.getEncoder();

    @Autowired
    IStoreService iStoreService;
    @Autowired
    IAccessoryService iAccessoryService;
    @Autowired
    IIconTypeService iIconTypeService;
    @Autowired
    IIconService iIconService;
    @Autowired
    IDeviceService iDeviceService;
    @Autowired
    IAreaService iAreaService;

    @RequestMapping(value = "/cityList", method = RequestMethod.POST)
    @ApiOperation(notes = "城市列表", httpMethod = "POST", value = "城市列表")
    public BaseRet<PageInfo<List<CityListRet>>> cityList(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody CityListParam param,
            BindingResult result) {

        BaseRet<PageInfo<List<CityListRet>>> ret = new BaseRet<PageInfo<List<CityListRet>>>();

        PageInfo<List<CityListRet>> pageInfo = new PageInfo<List<CityListRet>>();

        try {

            checkParam(result);

            int count = iStoreService.selectCityListByCount(param.getParentId(), param.getSearchCondition());
            pageInfo.setCount(count);
            List<CityListDto> list = iStoreService.selectCityListByPage(param.getStart(), param.getPageSize(), param.getParentId(), param.getSearchCondition());

            List<CityListRet> returnList = new ArrayList<CityListRet>();

            mapper.map(list, returnList);

            pageInfo.setRecords(returnList);

            ret.setData(pageInfo);
            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/provinceList", method = RequestMethod.POST)
    @ApiOperation(notes = "省份列表", httpMethod = "POST", value = "省份列表")
    public BaseRet<List<ProvinceListRet>> provinceList() {

        BaseRet<List<ProvinceListRet>> ret = new BaseRet<List<ProvinceListRet>>();

        try {


            List<LpAreaTbl> list = iStoreService.selectAreaList(1);
            List<ProvinceListRet> listRet = DozerMapperUtil.mapList(list, ProvinceListRet.class);

            ret.setData(listRet);
            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/searchCity", method = RequestMethod.POST)
    @ApiOperation(notes = "根据父级id查询城市列表", httpMethod = "POST", value = "根据父级id查询城市列表")
    public BaseRet<List<ProvinceListRet>> searchCity(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param,
            BindingResult result
    ) {

        BaseRet<List<ProvinceListRet>> ret = new BaseRet<List<ProvinceListRet>>();

        try {

            checkParam(result);

            List<LpAreaTbl> list = iAreaService.selectAreaList(param.getId());
            List<ProvinceListRet> listRet = DozerMapperUtil.mapList(list, ProvinceListRet.class);

            ret.setData(listRet);
            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateCitySort", method = RequestMethod.POST)
    @ApiOperation(notes = "修改城市排序", httpMethod = "POST", value = "修改城市排序")
    public BaseRet<String> updateCitySort(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateCitySortParam param,
            BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            LpAreaTbl lpAreaTbl = new LpAreaTbl();
            lpAreaTbl.setId(param.getId());
            lpAreaTbl.setSequence(String.valueOf(param.getSort()));

            if (iStoreService.updateArea(lpAreaTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateCityStatus", method = RequestMethod.POST)
    @ApiOperation(notes = "修改城市状态", httpMethod = "POST", value = "修改城市状态")
    public BaseRet<String> updateCityStatus(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateCourseTypeStatusParam param,
            BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            LpAreaTbl lpAreaTbl = new LpAreaTbl();
            lpAreaTbl.setId(param.getId());
            lpAreaTbl.setIsEnable(String.valueOf(param.getStatus()));

            if (iStoreService.updateArea(lpAreaTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/storeList", method = RequestMethod.POST)
    @ApiOperation(notes = "门店列表", httpMethod = "POST", value = "门店列表")
    public BaseRet<PageInfo<List<StoreListRet>>> storeList(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody StoreListParam param,
            BindingResult result) {

        BaseRet<PageInfo<List<StoreListRet>>> ret = new BaseRet<PageInfo<List<StoreListRet>>>();

        PageInfo<List<StoreListRet>> pageInfo = new PageInfo<List<StoreListRet>>();

        try {

            checkParam(result);

            if (param.getStoreId().size() <= 0) {
                param.setStoreId(null);
            }

            int count = iStoreService.selectByCount(param.getSearchCondition(), param.getStoreId());
            pageInfo.setCount(count);
            List<LpStoreTbl> list = iStoreService.selectByPage(param.getStart(), param.getPageSize(), param.getSearchCondition(), param.getStoreId());

            List<StoreListRet> listRet = new ArrayList<StoreListRet>();

            if (list != null && list.size() > 0) {

                for (LpStoreTbl value : list) {

                    StoreListRet storeListRet = new StoreListRet();
                    mapper.map(value, storeListRet);
                    listRet.add(storeListRet);

                }
            }

            pageInfo.setRecords(listRet);

            ret.setData(pageInfo);
            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/storeInfo", method = RequestMethod.POST)
    @ApiOperation(notes = "门店详情", httpMethod = "POST", value = "门店详情")
    public BaseRet<StoreInfoRet> storeInfo(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param,
            BindingResult result) {

        BaseRet<StoreInfoRet> ret = new BaseRet<StoreInfoRet>();

        StoreInfoRet storeInfoRet = new StoreInfoRet();

        try {

            checkParam(result);

            LpStoreTbl info = iStoreService.selectInfo(param.getId());
            mapper.map(info, storeInfoRet);

            //查询贴图
            LpAccessoryTbl pictrueInfo = iAccessoryService.selectInfo(info.getPictureId());
            storeInfoRet.setPictrueImg(pictrueInfo.getUrl());

            //查询城市id
            LpAreaTbl areaInfo = iAreaService.selectAreaInfo(info.getAreaId());
            LpAreaTbl cityInfo = iAreaService.selectAreaInfo(areaInfo.getParentId());

            //查询城市列表
            List<LpAreaTbl> list = iAreaService.selectAreaList(cityInfo.getParentId());
            List<ProvinceListRet> cityList = DozerMapperUtil.mapList(list, ProvinceListRet.class);
            storeInfoRet.setCityList(cityList);
            storeInfoRet.setParentId(cityInfo.getParentId());
            storeInfoRet.setCityId(cityInfo.getId());

            //查询区域列表
            List<LpAreaTbl> areaList = iAreaService.selectAreaList(cityInfo.getId());
            storeInfoRet.setAreaList(DozerMapperUtil.mapList(areaList, ProvinceListRet.class));

            ret.setData(storeInfoRet);
            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateStore", method = RequestMethod.POST)
    @ApiOperation(notes = "修改门店信息", httpMethod = "POST", value = "修改门店信息")
    public BaseRet<String> updateStore(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateStoreInfoParam param,
            BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            //判断图片id是否更改
            LpStoreTbl lpStoreTbl = new LpStoreTbl();
            mapper.map(param, lpStoreTbl);
            lpStoreTbl.setPictureId(iAccessoryService.isUpdateImg(param.getPictrueImg()));

            if (iStoreService.updateStore(lpStoreTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");


            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateStoreStatus", method = RequestMethod.POST)
    @ApiOperation(notes = "修改门店状态", httpMethod = "POST", value = "修改门店状态")
    public BaseRet<String> updateStoreStatus(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateCourseTypeStatusParam param,
            BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            LpStoreTbl lpStoreTbl = new LpStoreTbl();
            lpStoreTbl.setId(param.getId());
            lpStoreTbl.setStatus(String.valueOf(param.getStatus()));

            if (iStoreService.updateStore(lpStoreTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");

            } else {

                ret.setMsg("修改失败");
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/addStore", method = RequestMethod.POST)
    @ApiOperation(notes = "添加门店信息", httpMethod = "POST", value = "添加门店信息")
    public BaseRet<String> addStore(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody AddStoreInfoParam param,
            BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);
            LpStoreTbl lpStoreTbl = new LpStoreTbl();
            mapper.map(param, lpStoreTbl);
            lpStoreTbl.setPictureId(iAccessoryService.isUpdateImg(param.getPictrueImg()));
            lpStoreTbl.setInsertTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));
            if (iStoreService.addStore(lpStoreTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("添加成功");


            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("添加失败");
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/getStoreAlbum", method = RequestMethod.POST)
    @ApiOperation(notes = "获取门店相册", httpMethod = "POST", value = "获取门店相册")
    public BaseRet<List<GetsStoreAlbumRet>> getStoreAlbum(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param,
            BindingResult result) {

        BaseRet<List<GetsStoreAlbumRet>> ret = new BaseRet<List<GetsStoreAlbumRet>>();

        try {

            List<GetsStoreAlbumRet> listRet = new ArrayList<GetsStoreAlbumRet>();

            checkParam(result);

            List<GetsStoreAlbumDto> list = iStoreService.selectStorePhoto(param.getId());

            if (list != null && list.size() > 0) {

                mapper.map(list, listRet);
            }

            ret.setData(listRet);
            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateStoreAlbum", method = RequestMethod.POST)
    @ApiOperation(notes = "修改门店相册", httpMethod = "POST", value = "修改门店相册")
    public BaseRet<String> updateStoreAlbum(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateStoreAlbumParam param,
            BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            LpStorePhotoTbl lpStorePhotoTbl = new LpStorePhotoTbl();
            lpStorePhotoTbl.setId(param.getId());
            lpStorePhotoTbl.setSort(param.getSort());

            //新增图片
            LpAccessoryTbl lpAccessoryTbl = new LpAccessoryTbl();
            lpAccessoryTbl.setUrl(param.getUrl());
            lpAccessoryTbl.setName("门店相册");
            iAccessoryService.insert(lpAccessoryTbl);
            lpStorePhotoTbl.setPhotoId(lpAccessoryTbl.getId());

            if (iStoreService.updateStorePhoto(lpStorePhotoTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");


            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/addStoreAlbum", method = RequestMethod.POST)
    @ApiOperation(notes = "添加门店相册", httpMethod = "POST", value = "添加门店相册")
    public BaseRet<String> addStoreAlbum(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody AddStoreAlbumParam param,
            BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);
            if (iStoreService.insertStorePhoto(param.getSort(), param.getStoreId(), param.getUrl())) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("添加成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("添加失败");
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/delStoreAlbum", method = RequestMethod.POST)
    @ApiOperation(notes = "删除门店相册", httpMethod = "POST", value = "删除门店相册")
    public BaseRet<String> delStoreAlbum(
            @ApiParam(value = "请求参数", required = true) @Valid @RequestBody DelStoreAlbumParam param,
            BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);
            if (iStoreService.delStorePhoto(param.getId(), param.getPhotoId())) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("删除成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("删除失败");
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/storeIconType", method = RequestMethod.POST)
    @ApiOperation(notes = "门店icon分类列表", httpMethod = "POST", value = "门店icon分类列表")
    public BaseRet<List<StoreIconTypeRet>> storeIconType() {

        BaseRet<List<StoreIconTypeRet>> ret = new BaseRet<List<StoreIconTypeRet>>();

        try {

            List<LpIconTypeTbl> list = iIconTypeService.selectList();

            List<StoreIconTypeRet> listRet = DozerMapperUtil.mapList(list, StoreIconTypeRet.class);

            ret.setData(listRet);
            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/storeIconTypeInfo", method = RequestMethod.POST)
    @ApiOperation(notes = "门店icon分类详情", httpMethod = "POST", value = "门店icon分类详情")
    public BaseRet<StoreIconTypeRet> storeIconTypeInfo(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<StoreIconTypeRet> ret = new BaseRet<StoreIconTypeRet>();

        try {

            LpIconTypeTbl info = iIconTypeService.selectInfo(param.getId());

            StoreIconTypeRet infoRet = DozerMapperUtil.map(info, StoreIconTypeRet.class);

            ret.setData(infoRet);
            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateStoreIconType", method = RequestMethod.POST)
    @ApiOperation(notes = "修改门店icon分类", httpMethod = "POST", value = "修改门店icon分类")
    public BaseRet<String> updateStoreIconType(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateStoreIconTypeParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            LpIconTypeTbl lpIconTypeTbl = new LpIconTypeTbl();
            mapper.map(param, lpIconTypeTbl);

            if (iIconTypeService.update(lpIconTypeTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateStoreIconTypeStatus", method = RequestMethod.POST)
    @ApiOperation(notes = "修改门店icon分类状态", httpMethod = "POST", value = "修改门店icon分类状态")
    public BaseRet<String> updateStoreIconTypeStatus(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateStatusParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            LpIconTypeTbl lpIconTypeTbl = new LpIconTypeTbl();
            lpIconTypeTbl.setId(param.getId());
            lpIconTypeTbl.setIsDelete(param.getStatus());

            if (iIconTypeService.update(lpIconTypeTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/addStoreIconType", method = RequestMethod.POST)
    @ApiOperation(notes = "添加门店icon分类", httpMethod = "POST", value = "添加门店icon分类")
    public BaseRet<String> addStoreIconType(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody AddStoreIconTypeParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            LpIconTypeTbl lpIconTypeTbl = new LpIconTypeTbl();
            mapper.map(param, lpIconTypeTbl);

            if (iIconTypeService.insert(lpIconTypeTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("添加成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("添加失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/deleteStoreIconType", method = RequestMethod.POST)
    @ApiOperation(notes = "删除门店icon分类", httpMethod = "POST", value = "删除门店icon分类")
    public BaseRet<String> deleteStoreIconType(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            if (iIconTypeService.delete(param.getId())) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("删除成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("删除失败");

            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/storeIconList", method = RequestMethod.POST)
    @ApiOperation(notes = "门店icon列表", httpMethod = "POST", value = "门店icon列表")
    public BaseRet<List<IconListRet>> storeIconList(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<List<IconListRet>> ret = new BaseRet<List<IconListRet>>();

        try {

            List<IconListDto> list = iIconService.selectList(param.getId());

            List<IconListRet> listRet = DozerMapperUtil.mapList(list, IconListRet.class);

            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setData(listRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/storeIconInfo", method = RequestMethod.POST)
    @ApiOperation(notes = "门店icon详情", httpMethod = "POST", value = "门店icon详情")
    public BaseRet<IconListRet> storeIconInfo(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<IconListRet> ret = new BaseRet<IconListRet>();

        try {

            IconListDto info = iIconService.selectInfo(param.getId());
            IconListRet infoRet = DozerMapperUtil.map(info, IconListRet.class);
            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setData(infoRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateStoreIcon", method = RequestMethod.POST)
    @ApiOperation(notes = "修改门店icon", httpMethod = "POST", value = "修改门店icon")
    public BaseRet<String> updateStoreIcon(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateStoreIconParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            LpIconTbl lpIconTbl = new LpIconTbl();
            lpIconTbl.setId(param.getId());
            lpIconTbl.setIconName(param.getIconName());
            lpIconTbl.setKeyWord(param.getKeyWord());

            //判断是否更新图标
            if (param.getIconIsUpdate() == 1) {

                //保存新图标
                LpAccessoryTbl lpAccessoryTbl = new LpAccessoryTbl();
                lpAccessoryTbl.setInsertTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));
                lpAccessoryTbl.setName("场馆设备");
                lpAccessoryTbl.setUrl(param.getIconUrl());

                iIconService.insertAccessory(lpAccessoryTbl);
                lpIconTbl.setIconId(lpAccessoryTbl.getId());

            }

            if (iIconService.update(lpIconTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("修改成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("修改失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/addStoreIcon", method = RequestMethod.POST)
    @ApiOperation(notes = "添加门店icon", httpMethod = "POST", value = "添加门店icon")
    public BaseRet<String> addStoreIcon(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody AddStoreIconParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            LpIconTbl lpIconTbl = new LpIconTbl();
            lpIconTbl.setIconName(param.getIconName());
            lpIconTbl.setKeyWord(param.getKeyWord());
            lpIconTbl.setInsertTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));
            lpIconTbl.setTypeId(param.getTypeId());

            //保存新图标
            LpAccessoryTbl lpAccessoryTbl = new LpAccessoryTbl();
            lpAccessoryTbl.setInsertTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));
            lpAccessoryTbl.setName("场馆设备");
            lpAccessoryTbl.setUrl(param.getIconUrl());
            iIconService.insertAccessory(lpAccessoryTbl);

            lpIconTbl.setIconId(lpAccessoryTbl.getId());

            if (iIconService.insert(lpIconTbl)) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("添加成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("添加失败");
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/deleteStoreIcon", method = RequestMethod.POST)
    @ApiOperation(notes = "删除门店icon", httpMethod = "POST", value = "删除门店icon")
    public BaseRet<String> deleteStoreIcon(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            if (iIconService.delete(param.getId())) {

                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
                ret.setMsg("删除成功");

            } else {

                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                ret.setMsg("删除失败");

            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/storeDeviceList", method = RequestMethod.POST)
    @ApiOperation(notes = "门店设备列表", httpMethod = "POST", value = "门店设备列表")
    public BaseRet<List<DeviceListRet>> storeDeviceList(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<List<DeviceListRet>> ret = new BaseRet<List<DeviceListRet>>();

        try {

            List<LpEquipmentInfoTbl> list = iDeviceService.selectStoreDeviceList(param.getId());
            List<DeviceListRet> listRet = DozerMapperUtil.mapList(list, DeviceListRet.class);

            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setData(listRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/storeDeviceInfo", method = RequestMethod.POST)
    @ApiOperation(notes = "设备详情", httpMethod = "POST", value = "设备详情")
    public BaseRet<DeviceListRet> storeDeviceInfo(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<DeviceListRet> ret = new BaseRet<DeviceListRet>();

        try {


            LpEquipmentInfoTbl info = iDeviceService.selectDeviceInfo(param.getId());
            DeviceListRet infoRet = DozerMapperUtil.map(info, DeviceListRet.class);

            String deviceIdStr = new String(decoder.decode(infoRet.getEquipmentId()), "UTF-8");

            JSONArray deviceId = JSONArray.parseArray(deviceIdStr);
            infoRet.setEquipmentId(StringUtils.join(deviceId, ","));
            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setData(infoRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateStoreDevice", method = RequestMethod.POST)
    @ApiOperation(notes = "修改设备信息", httpMethod = "POST", value = "修改设备信息")
    public BaseRet<String> updateStoreDevice(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateStoreDeviceParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            LpEquipmentInfoTbl lpEquipmentInfoTbl = new LpEquipmentInfoTbl();
            lpEquipmentInfoTbl.setId(param.getId());
            lpEquipmentInfoTbl.setEquipmentType(param.getEquipmentType());
            lpEquipmentInfoTbl.setName(param.getName());
            /*String deviceIdStr = "[" + param.getEquipmentId() + "]";
            lpEquipmentInfoTbl.setEquipmentId(encoder.encodeToString(deviceIdStr.getBytes()));*/

            if (iDeviceService.updateDevice(lpEquipmentInfoTbl)) {

                ret.setMsg("修改成功");
                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

            } else {

                ret.setMsg("修改失败");
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/addStoreDevice", method = RequestMethod.POST)
    @ApiOperation(notes = "添加设备信息", httpMethod = "POST", value = "修改设备信息")
    public BaseRet<String> addStoreDevice(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody AddStoreDeviceParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            LpEquipmentInfoTbl lpEquipmentInfoTbl = new LpEquipmentInfoTbl();
            lpEquipmentInfoTbl.setStoreId(param.getStoreId());
            lpEquipmentInfoTbl.setEquipmentType(param.getEquipmentType());
            lpEquipmentInfoTbl.setName(param.getName());
            String deviceIdStr = "[" + param.getEquipmentId() + "]";
            lpEquipmentInfoTbl.setEquipmentId(encoder.encodeToString(deviceIdStr.getBytes()));

            //检查设备id是否存在
            List<LpEquipmentInfoTbl> deviceList = iDeviceService.selectStoreDeviceListByDevId(lpEquipmentInfoTbl.getEquipmentId());

            if (deviceList != null && deviceList.size() > 0) {

                ret.setMsg("设备id已存在");
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);

            } else {

                //写入数据
                lpEquipmentInfoTbl.setInsertTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));
                lpEquipmentInfoTbl.setUseUserId(0);

                String uuid = CommonFunctionUtil.createUuid();

                lpEquipmentInfoTbl.setQrcode(Constant.httpConfig.deviceDomain + "new_" + uuid);

                if (iDeviceService.addDevice(lpEquipmentInfoTbl, uuid)) {

                    ret.setMsg("添加成功");
                    ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

                } else {

                    ret.setMsg("添加失败");
                    ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                }

            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/delStoreDevice", method = RequestMethod.POST)
    @ApiOperation(notes = "删除设备", httpMethod = "POST", value = "删除设备")
    public BaseRet<String> delStoreDevice(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {


            if (iDeviceService.delDevice(param.getId())) {

                ret.setMsg("删除成功");
                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

            } else {

                ret.setMsg("删除失败");
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/stopLighting", method = RequestMethod.POST)
    @ApiOperation(notes = "关闭灯光", httpMethod = "POST", value = "关闭灯光")
    public BaseRet<String> stopLighting(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            //查询设备详情
            LpEquipmentInfoTbl deviceInfo = iDeviceService.selectDeviceInfo(param.getId());
            //门店id
            int storeId = deviceInfo.getStoreId();

            //清空场馆人数
            LpStoreTbl lpStoreTbl = new LpStoreTbl();
            lpStoreTbl.setId(storeId);
            lpStoreTbl.setOnlineSum(0);

            if (iStoreService.updateStore(lpStoreTbl)) {

                //删除场馆人数记录
                iStoreService.delStoreOnLine(storeId);
                //关闭设备
                LpEquipmentInfoTbl lpEquipmentInfoTbl = new LpEquipmentInfoTbl();
                lpEquipmentInfoTbl.setState("0");
                lpEquipmentInfoTbl.setId(deviceInfo.getId());
                iDeviceService.updateDevice(lpEquipmentInfoTbl);

                ret.setMsg("操作成功");
                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

            } else {

                ret.setMsg("操作失败");
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/clearDeviceUser", method = RequestMethod.POST)
    @ApiOperation(notes = "清除用户和设备的关系", httpMethod = "POST", value = "清除用户和设备的关系")
    public BaseRet<String> clearDeviceUser(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            //查询设备详情
            LpEquipmentInfoTbl lpEquipmentInfoTbl = new LpEquipmentInfoTbl();
            lpEquipmentInfoTbl.setId(param.getId());
            lpEquipmentInfoTbl.setUseUserId(0);
            lpEquipmentInfoTbl.setState("0");

            if (iDeviceService.updateDevice(lpEquipmentInfoTbl)) {

                ret.setMsg("操作成功");
                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

            } else {

                ret.setMsg("操作失败");
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/getStoreIconList", method = RequestMethod.POST)
    @ApiOperation(notes = "门店图标列表", httpMethod = "POST", value = "门店图标列表")
    public BaseRet<List<StoreIconListRet>> getStoreIconList(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<List<StoreIconListRet>> ret = new BaseRet<List<StoreIconListRet>>();

        try {

            checkParam(result);

            List<StoreIconListDto> list = iStoreService.selectStoreIconList(param.getId());

            List<StoreIconListRet> listRet = DozerMapperUtil.mapList(list, StoreIconListRet.class);

            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setData(listRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/updateStoreIconSort", method = RequestMethod.POST)
    @ApiOperation(notes = "修改门店图标排序", httpMethod = "POST", value = "修改门店图标排序")
    public BaseRet<String> updateStoreIconSort(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody UpdateCitySortParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            LpStoreIconTbl lpStoreIconTbl = new LpStoreIconTbl();
            lpStoreIconTbl.setId(param.getId());
            lpStoreIconTbl.setSort(param.getSort());

            if (iStoreService.updateStoreIcon(lpStoreIconTbl)) {

                ret.setMsg("操作成功");
                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

            } else {

                ret.setMsg("操作失败");
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/delStoreIcon", method = RequestMethod.POST)
    @ApiOperation(notes = "删除门店图标", httpMethod = "POST", value = "删除门店图标")
    public BaseRet<String> delStoreIcon(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            if (iStoreService.delStoreIcon(param.getId())) {

                ret.setMsg("操作成功");
                ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

            } else {

                ret.setMsg("操作失败");
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/addStoreIcons", method = RequestMethod.POST)
    @ApiOperation(notes = "添加门店图标排序", httpMethod = "POST", value = "添加门店图标排序")
    public BaseRet<String> addStoreIcons(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody AddStoreIconsParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {

            checkParam(result);

            //检查是否已存在
            List<LpStoreIconTbl> list = iStoreService.selectStoreIcon(param.getStoreId(), param.getIconId());
            if (list != null && list.size() > 0) {

                ret.setMsg("已经存在");
                ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);

            } else {

                long count = iStoreService.countStoreIcon(param.getStoreId());
                count++;

                LpStoreIconTbl lpStoreIconTbl = new LpStoreIconTbl();
                lpStoreIconTbl.setStoreId(param.getStoreId());
                lpStoreIconTbl.setIconId(param.getIconId());
                lpStoreIconTbl.setSort((int) count);

                if (iStoreService.addStoreIcon(lpStoreIconTbl)) {

                    ret.setMsg("添加成功");
                    ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

                } else {

                    ret.setMsg("添加失败");
                    ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
                }

            }


        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/getIconList", method = RequestMethod.POST)
    @ApiOperation(notes = "图标列表", httpMethod = "POST", value = "图标列表")
    public BaseRet<List<IconListRet>> getIconList() {
        BaseRet<List<IconListRet>> ret = new BaseRet<List<IconListRet>>();

        try {


            List<LpIconTbl> list = iStoreService.selectIconList();
            List<IconListRet> listRet = DozerMapperUtil.mapList(list, IconListRet.class);

            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setData(listRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/closeAllDevice", method = RequestMethod.POST)
    @ApiOperation(notes = "关闭指定门店的所有设备", httpMethod = "POST", value = "关闭指定门店的所有设备")
    public BaseRet<String> closeAllDevice(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<String> ret = new BaseRet<String>();

        try {


            //重置所有设备的状态为已关闭，同时清除使用者id
            iDeviceService.clearStateOrUserId(param.getId());

            //清空场馆人数
            LpStoreTbl lpStoreTbl = new LpStoreTbl();
            lpStoreTbl.setId(param.getId());
            lpStoreTbl.setOnlineSum(0);
            iStoreService.updateStore(lpStoreTbl);

            //删除场馆人数记录
            iStoreService.delStoreOnLine(param.getId());


            ret.setMsg("操作成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }


    @RequestMapping(value = "/getStoreUserId", method = RequestMethod.POST)
    @ApiOperation(notes = "获取场馆所有用户id", httpMethod = "POST", value = "获取场馆所有用户id")
    public BaseRet<GetStoreUserIdRet> getStoreUserId(@ApiParam(value = "请求参数", required = true) @Valid @RequestBody ActionLibraryInfoParam param, BindingResult result) {

        BaseRet<GetStoreUserIdRet> ret = new BaseRet<GetStoreUserIdRet>();

        try {

            GetStoreUserIdRet getStoreUserIdRet = new GetStoreUserIdRet();

            List<LpStoresOnlineTbl> list = iStoreService.selectStoresOnlineList(param.getId());
            List<Integer> userId = new ArrayList<Integer>();
            for (LpStoresOnlineTbl value : list) {
                userId.add(value.getId());
            }
            getStoreUserIdRet.setUserId(userId);

            ret.setMsg("查询成功");
            ret.setCode(ApiResponseEnum.API_RESPONSE_SUCCESS);
            ret.setData(getStoreUserIdRet);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.setCode(ApiResponseEnum.API_RESPONSE_ERROR);
            ret.setMsg(e.getMessage());
        }

        return ret;
    }
}
